package com.xiangxiangjd.kj.papersstar.serviceImpl;

import com.xiangxiangjd.kj.papersstar.controller.helper.$;
import com.xiangxiangjd.kj.papersstar.bean.Answer;
import com.xiangxiangjd.kj.papersstar.mapper.AnswerMapper;
import com.xiangxiangjd.kj.papersstar.service.AnswerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiangxiangjd.kj.papersstar.bean.result.ResultPage;
import com.xiangxiangjd.kj.papersstar.controller.model.ApiResultModel;

import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 肖守凯
 * @since 2021-01-21
 */
@Service
public class AnswerServiceImpl extends ServiceImpl<AnswerMapper, Answer> implements AnswerService {
    /** 添加Answer
     * @param answer  前端传进的参数
     * @return 返回统一信息
     */
    @Override
    public ApiResultModel addAnswer(Answer answer  ) {
           if(this.save(answer )){
               return $.success();
           }else{
                return $.error("添加失败");
           }
    }
    /** 编辑跳转页面的回显数据Answer
     * @param id  前端传进的参数
     * @return 返回实体类
     */
    @Override
    public Answer selectAnswerByIdAnswer(String id ){
            return this.getById(id);
    }


    /** 编辑Answer
     * @param answer  前端传进的参数
     * @return 返回统一信息
     */
    @Override
    public ApiResultModel editAnswer(Answer answer  ) {
           if(this.updateById(answer )){
               return $.success();
           }else{
                return $.error("编辑失败");
           }
    }
    /** 删除一条Answer
     * @param ids  前端传进的ID
     * @return 返回统一信息
     */
    @Override
    public   ApiResultModel delAnswers(  List ids ){

        int i = baseMapper.deleteBatchIds(ids);

        return $.success(i);

    }

   /** 分页查询Answer
     * @param page  页码
     * @param limit  查几条
     * @param answer  前端传进的参数
     * @return 返回统一分页信息
     */
    @Override
    public  ResultPage findAnswerByPage(Integer page, Integer limit,Answer answer){
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page", (page - 1) * limit);
        paramMap.put("limit", limit);
        paramMap.put("answer", answer);
        List<Answer> list = baseMapper.selectMyPage(paramMap);
        Integer count = baseMapper.countMyPage(paramMap);
        ResultPage<Answer> resultPage = new ResultPage<>();
        resultPage.setCode(0);
        resultPage.setCount(count);
        resultPage.setMsg("成功");
        resultPage.setData(list);
        return resultPage;
    }


}
